package librarianPanels;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JLabel;

import java.awt.Dimension;
import java.awt.Font;
import javax.swing.border.LineBorder;
import java.awt.Color;
import javax.swing.JTextField;
import javax.swing.JButton;

import clientGUI.MainGUI;
import clientGUI.PanelDesign;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JPanel;


/**
 * @author Shay
 * Borrow Book Panel
 *
 */
public class BorrowBookPanel extends PanelDesign{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public JTextField textFieldBorrowBookID;
	public JTextField textFieldSubsID;
	public JTextField textFieldCopy;
	public JButton btnSubmit;
	/**
	 * 
	 */
	/**
	 * 
	 */
	public BorrowBookPanel() {
		super();
		setBorder(new LineBorder(new Color(0, 0, 0), 3, true));
		setLayout(null);
		setPreferredSize(new Dimension(644, 462));
		JLabel lblN = new JLabel("Borrow A Book");
		lblN.setFont(new Font("Tahoma", Font.PLAIN, 29));
		lblN.setBounds(211, 27, 206, 35);
		add(lblN);
		
		JPanel panel = new JPanel();
		panel.setBounds(211, 136, 189, 146);
		add(panel);
		panel.setLayout(null);
		
		textFieldBorrowBookID = new JTextField();
		textFieldBorrowBookID.setBounds(103, 27, 86, 20);
		panel.add(textFieldBorrowBookID);
		textFieldBorrowBookID.setColumns(10);
		
		JLabel lblBookId = new JLabel("Book ID:");
		lblBookId.setBounds(0, 30, 77, 14);
		panel.add(lblBookId);
		lblBookId.setFont(new Font("Tahoma", Font.PLAIN, 15));
		
		JLabel lblNewLabel = new JLabel("Subscriber ID:");
		lblNewLabel.setBounds(0, 1, 102, 14);
		panel.add(lblNewLabel);
		lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 15));
		
		textFieldSubsID = new JTextField();
		textFieldSubsID.setBounds(103, 0, 86, 20);
		panel.add(textFieldSubsID);
		textFieldSubsID.setColumns(10);
		
		btnSubmit = new JButton("Borrow");
		btnSubmit.setBounds(37, 100, 109, 35);
		panel.add(btnSubmit);
		btnSubmit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			{
				if(!MainGUI.testmode)
				{
					int n = JOptionPane.showConfirmDialog(new JFrame(),	"Are you really that sure?","An Inane Question",JOptionPane.YES_NO_OPTION);		
					if(n==1)		
						return;
				}
				String[] s=new String[4];
				s[0]="BorowBook";
				s[1]=textFieldBorrowBookID.getText();
				s[2]=textFieldSubsID.getText();
				s[3]=textFieldCopy.getText();
				if(MainGUI.isMsgEmpty(s))
				{
					JOptionPane.showMessageDialog(null,"One of the fields or more are empty!");
					return;
				}
				if(!MainGUI.isNumber(s[1]) || !MainGUI.isNumber(s[2]) || !MainGUI.isNumber(s[3]))
				{
					JOptionPane.showMessageDialog(null,"Only Digits");
					return;
				}
				MainGUI.OBLClient.handleMessageFromClient(s);
			}
		});
		btnSubmit.setFont(new Font("Tahoma", Font.PLAIN, 13));
		
		JLabel lblNewLabel_1 = new JLabel("Copy:");
		lblNewLabel_1.setBounds(0, 57, 38, 20);
		panel.add(lblNewLabel_1);
		lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 15));
		
		textFieldCopy = new JTextField();
		textFieldCopy.setBounds(103, 57, 86, 20);
		panel.add(textFieldCopy);
		textFieldCopy.setColumns(10);
		
		
		JLabel label = new JLabel("Please Enter Details:");
		label.setFont(new Font("Tahoma", Font.BOLD, 16));
		label.setBounds(214, 88, 180, 33);
		add(label);
		remove(background);
		add(background);
	}
	
	/**
	 * Show message result 
	 * @param info
	 */
	public static void ShowMsgFromServer(String info)
	{
		if(info.compareTo("1")==0)
		{
			info=new String("The action succeeded!");
		}
		JOptionPane.showMessageDialog(null,info);
	}
	
	

}
